#!/bin/bash
# Walking program to execute commands across multiple linux nodes
# using SSH connections

#read -s -p "Enter Password: " passwd
#echo ""

function printhelp {
	echo "Usage: AGWalker commands.list nodes.list"
}

#read in list of nodes to walk
echo "Reading walk.list"
n=0
while read line
do
	nodes[$n]=$line
	#echo "$n = $line"
	n=$[$n + 1]	
done < walk.list
#echo ${nodes[*]}
echo "Done reading walk.list"

#read in command list
echo "Reading walk.cmd"
c=0
while read line
do
	cmd[$c]=$line
	#echo "$c = $line"
	c=$[$c + 1]
done < walk.cmd
#echo ${cmd[*]}
echo "Done reading walk.cmd"


#iterate through list of nodes
echo "Starting to walk..."
for node in ${nodes[@]}
do
	ssh user@${node}
	#send password somehow?
	for (( command = 0 ; command < ${#cmd[@]} ; command++ ))
	do
		${cmd[$command]}
	done
	exit
done
